import logging
import os
from logging.handlers import TimedRotatingFileHandler

class Logger():
    def __init__(self, log_name):
        self.text_logger_url = "./log"
        
        # 配置日志
        # log_name一定要不同 不然指定不同路径也会写到一个log下面
        logger = logging.getLogger(log_name)
        logger.setLevel(logging.INFO)

        if not os.path.exists(self.text_logger_url):
            os.makedirs(self.text_logger_url)

        file_handler = TimedRotatingFileHandler(
            f'{self.text_logger_url}/{log_name}.log',
            encoding='utf-8',
            when='midnight',
            interval=1)
        file_handler.setLevel(logging.INFO)

        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        file_handler.setFormatter(formatter)

        logger.addHandler(file_handler)

        self.logger = logger
        self.log_name = log_name

    def info(self, msg):
        self.logger.info(msg)

    def debug(self, msg):
        self.logger.debug(msg)


    def warning(self, msg):
        self.logger.warning(msg)


    def error(self, msg):
        self.logger.error(msg)



llm_logger = Logger('llm_log')
api_logger = Logger('api_log')
